<!DOCTYPE html>
<html>
<head>
    <title>我的评论</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            var userId = user.id;
            //首先我们需要获取当前页的标签
            var currentInput = $('#currentPage');
            //因为我们手机滚动之前的数据就没有了,只有当前查出来的不合理
            var arr = [];
            var pages = 1;

            function query() {
                //获取当前页
                var currentPage = currentInput.val();
                $.get('/allMessages/' + userId, {currentPage: currentPage}, function (data) {
                    console.log(data);
                    pages = data.travelCommentPageInfo.pages;
                    //把两个数组的数据合并在一起,就可以滚动了
                    $.merge(arr, data.travelCommentPageInfo.list);
                    var json = {list: arr};
                    console.log(json);
                    $('.aui-scrollView').renderValues(json, {
                        getHref: function (item, value) {
                            var href = $(item).data("href");
                            var authorId = $(item).prev().data("id");
                            $(item).attr("href", href + value+"&authorId="+authorId);
                        },
                        getHref2: function (item, value) {
                            var href = $(item).data("href");
                            $(item).attr("href", href + value);
                        },
                        getNum: function (item, value) {
                            console.log(value);
                            if (value == 1) {
                                $(item).html("未读");
                            } else if (value == 0) {
                                $(item).html("已读");
                                $(item).css('color', 'blue');
                            }
                        }
                    });

                });
                currentInput.val(parseInt(currentPage) + 1);
            }

            query();
            $('._j_add_more_button').click(function () {
                var currentPage = currentInput.val();
                if (currentPage <= pages) {
                    query();
                } else {
                    $(document).dialog({
                        type: 'notice',
                        infoText: '没有更多私信了!!!',
                        autoClose: 1000
                    });
                }
            });
        })
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="/mine/message.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的评论列表</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>我的评论</span>
        </a>
    </li>
</ul>
<div id="comment">
    <div class="aui-scrollView">
        <div  render-loop="list">
            <div class="container row comment">
                <div class="col-2 comment-head">
                    <a data-href="/userProfiles.html?authorId=" render-key="list.authorId" render-fun="getHref2" class="aui-news-item">
                        <img class="rounded-circle" render-src="list.user.headImgUrl">
                    </a>
                </div>
                <div class="col comment-right">
                    <p class="authorName"><span render-html="list.user.nickName"></span></p>
                    <span class="myclass">
                            <i class="time">评论时间:</i>
                        </span>
                    <span class="comment-date" render-html="list.createTime"></span>
                    <p class="read" style="color: red" render-key="list.state" render-fun="getNum"></p>
                    <div class="comment-content">
                        <a href="strategyComment.html">
                            <hr>
                            内容:<p render-html="list.content"></p>
                        </a>
                    </div>

                    <ul class="comment-img">
                        <li>
                            <span render-attr="data-id=list.authorId"></span>
                            <a data-href="/travelComment.html?travelId="  render-key="list.travel.id" render-fun="getHref" class="aui-news-item">
                            <img render-src="list.travel.coverUrl">
                            </a>
                        </li>
                    </ul>
                    <hr>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>
<div class="aui-news-box" style="text-align: center">
    <a class="more-list _j_add_more_button">更多私信</a>
</div>

</body>
</html>